package com.example.testanimation.graphics.xfermode;

import android.content.Context;
import android.graphics.*;
import android.util.AttributeSet;
import android.view.View;
import com.scenic.rd_android.R;

/**
 * Created by scenic on 2015/3/29.
 */
public class RoundRectView extends View {

    private Bitmap mResBitmap;
    private Bitmap bitmapOutput;

    private Paint paint = new Paint();
    public RoundRectView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initLayout();
    }

    private void initLayout() {

        setLayerType(LAYER_TYPE_SOFTWARE,null);

        mResBitmap = BitmapFactory.
                decodeResource(getResources(), R.mipmap.png_test);
        bitmapOutput = Bitmap.createBitmap(mResBitmap.getWidth(),mResBitmap.getHeight(), Bitmap.Config.ARGB_8888);

        paint.setAntiAlias(true);

        setBackgroundColor(Color.BLUE);

        Canvas canvas = new Canvas(bitmapOutput);

        paint.setColor(Color.BLACK);
        canvas.drawCircle(mResBitmap.getWidth()/2,
                mResBitmap.getHeight()/2,
                mResBitmap.getWidth()/2,paint);

        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        canvas.drawBitmap(mResBitmap,0,0,paint);
//        canvas.drawRoundRect(0,0,mResBitmap.getWidth(),mResBitmap.getHeight(),50,50,paint);


    }


    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawBitmap(bitmapOutput,0,0,null);
    }
}
